
package com.weiqiao.order.repository.impl;

import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.order.repository.IOrderRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 订单持久化层
 *
 * @author ChenYF
 */
@Repository("OrderRepositoryImpl")
public class OrderRepositoryImpl extends BaseMongoDaoImpl implements IOrderRepository {

    private String collectionName = "orders_";

    @Override
    public int countNum(int company_id, Bson filter) {
        return this.statististics(collectionName + company_id, filter);
    }

    @Override
    public boolean addOrder(int company_id, String json) {
        return this.inSertCommon(collectionName + company_id, json);
    }

    @Override
    public List<String> getOrderListAndPage(int company_id, Bson filter, Bson sort, int skip, int pageSize) {
        return this.findFilterSortSkipLimit(collectionName + company_id, filter, sort, skip, pageSize);
    }

    @Override
    public List<String> getPage(int company_id, Bson filter, Pageable pageable) {
        return super.getListAndPage(collectionName + company_id, filter, pageable);
    }

    @Override
    public List<String> getOrderList(int company_id, Bson filter) {
        return this.findFilter(collectionName + company_id, filter);
    }

    @Override
    public boolean updteOrder(int company_id, Bson bson, Document doc, Boolean batch) {
        if (batch) {
            return this.updateMany(collectionName + company_id, bson, doc, false);
        } else {
            return this.updateOne(collectionName + company_id, bson, doc, false);
        }
    }

    @Override
    public String getOrderDetail(int companyid, Bson filter) {
        return this.findOne(collectionName + companyid, filter);
    }


}
